<?php

namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class GroupResource extends JsonResource
{
	public function toArray($request)
	{
		$resource = $this->resource;
		
		return [
			'id' => (int)$resource->id,
			'user_id'                   => (int)$resource->user_id,
			'user_avatar_url'           => img_path($resource->user->avatar),
			'user_name'           => $resource->user->name,
			'product'                   => new ProductListResource($resource->product),
			'is_finished' =>$resource->is_finished,
			'group_expired_at' =>$resource->group_expired_at,
			'join_number' => $resource->records ? $resource->records->count() : 0,
			'join_records' => GroupRecordsResource::collection($resource->records) ?? null ,
			'joins_rate' => $resource->product->group_number  ?  config("site.joins.{$resource->product->group_number}") : [],
			
		];
	}
}
